<?php include TMPL_PATH.'public/header.phtml';?>
<div class="subnav">
    <div class="content-menu ib-a blue line-x">
    <a href='<?php echo U('order/order_list');?>' ><em>订单列表</em></a><span>|</span><a href='<?php echo U('order/order_edit', 'oid='.$order['id']);?>'><em>订单详细信息</em></a><span>|</span>
        <a href='javascript:;' class="on"><em>订单产品信息</em></a> <span>|</span>&nbsp;订单号:<?php echo $order['order_sn'];?>
    </div>
</div>

<style type='text/css'>
.table_form tbody td{ border: 1px solid #EEEEEE;}
.division {
    background: none repeat scroll 0 0 #FFFFFF;
    border-color: #CCCCCC #BEC6CE #BEC6CE #CCCCCC;
    border-style: solid;
    border-width: 1px 2px 2px 1px;
    line-height: 150%;
    white-space: normal;
}
.division table {
    margin: 0;
    padding: 0;
}
.division th, .division td {
    border-color: #FFFFFF #DBE2E7 #DDDDDD #FFFFFF;
    border-left: 1px solid #FFFFFF;
    border-right: 1px solid #DBE2E7;
    border-style: solid;
    border-width: 1px;
    padding: 5px;
    vertical-align: top;
}
.division th {
    background: none repeat scroll 0 0 #E2E8EB;
    border-right: 1px solid #CCCCCC;
    font-size: 14px;
    text-align: right;
    white-space: nowrap;
    width: 140px;
}
.gridlist th{
	text-align:center;
	font-weight: bold;
	font-size: 12px;
}
.order_th{font-size: 14px; color: rgb(0, 0, 0); font-weight: bold; margin: 10px;overflow:hidden;}
</style>
<div class="pad-10">
<div class="col-tab">
<form name="myform" id="myform" action="__SELF__" method="post">
<div id="div_setting_1" class="contentList division pad-10">
<div class="table-grid" style="border: 1px solid #efefef;">
	<table width="100%" cellspacing="0" cellpadding="2" border="0" class="gridlist" id="order_items"> 
		<thead> 
			<tr>
			 <th style="width:150px;">货号</th> 
			 <th style="width:300px;">商品名称</th> 
			 <th style="width:100px;">价格</th> 
			 <th style="width:100px;">购买数量</th> 
			 <th style="width:100px;">小计</th> 
			 <th style="width:100px;"></th> 
			</tr> 
		</thead> 
		<tbody>
		<?php 
		if(isset($productList) && $productList):
			foreach ($productList as $product):
		?>
			<tr>
				<input type="hidden" value="<?php echo $product['id'];?>" name="oiid[<?php echo $product['id'];?>]"> 
				<input type="hidden" value="<?php echo $product['product_id'];?>" name="goods_id[<?php echo $product['id'];?>]"> 
				<td align="center"><?php echo $product['product_sn'];?></td> 
				<td><?php echo $product['product_name'];if($product['attr']){echo ' ( '. $product['attr'] . ' )';}?></td> 
				<td align="center"><input type="text" size="8" value="<?php echo $product['pay_price'];?>" name="goods_price[<?php echo $product['id'];?>]" autocomplete="off"></td> 
				<td align="center"><input type="text" size="4" value="<?php echo $product['qty'];?>" name="goods_number[<?php echo $product['id'];?>]" autocomplete="off"></td> 
				<td align="center"><?php echo $product['total_amount'];?></td> 
				<td align="center"><a href="<?php echo U('order/order_product_delete', 'oid='.$order['id'].'&oiid='.$product['id'])?>">删除</a></td> 
			</tr>
		<?php 
			endforeach;
		endif;
		?>
		</tbody> 
	</table> 
	<table width="100%" cellspacing="0" cellpadding="2" border="0" class="gridlist">
	 <tbody>
	 <tr>
			<td style="text-align: right;width:100%">
				产品总金额：<?php echo $order['product_amount'];?>
			</td>
		</tr>
	 	</tbody>
	</table>
</div>
<div class="bk15"></div>
<div style="float:right">
    <input name="dosubmit" type="submit" value="更新商品"  class="button" id="dosubmit" /></div>
</div>
</form>

<div class="bk30"></div>
<div class="order_th">添加新商品</div>
	<table width="100%" cellspacing="0" cellpadding="2" border="0" class="gridlist">
	 <tbody>
	 	<tr> 
	 		<td style="text-align:left">输入商品货号：<input type="text" name="product_sn" id="product_sn" class="input-style" autocomplete="off"> 
	 		<input type="button" value="搜索" onclick="add_new_product();" name="newbtn" class="button" id="newbtn"></td> 
	 	</tr> 
	 	</tbody>
	</table>
	
<div class="bk15"></div>
<form name="myform" id="myform" action="__SELF__" method="post">
<div id="div_setting_2" class="contentList division pad-10">
<table width="100%" class="table_form">
	<tbody>
	<tr> 
		<th width="100">产品名称：</th> 
		<td id="goods_name"></td>
		</tr>
		<tr>
		<th>销售价格：</th> 
		<td id="sell_price"></td>
		</tr>
		<tr>
		<th>库存：</th> 
		<td id="stock"></td>
		</tr>
		<tr>
		<th>属性：<input type="hidden" id="spec_count" name="spec_count" value="0" /></th> 
		<td id="goods_attr">
			<?php if (!empty($attributeList)): ?>
			<table width="100%" class="table_form ">
				<tbody>
				<?php 
				foreach ($attributeList as $attribute):
					if(empty($attribute['values'])) continue;
				?>
				<tr>
			      <th width="50"><?php echo $attribute['name'] ?>：</th>
			      <td style="line-height:25px">
			      	<?php foreach ($attribute['values'] as $attr):?>
			      	<label><input type="radio" value="<?php echo $attr['id']?>" name="field_<?php echo $attribute['id']?>"> <?php echo $attr['name']?></label>
			      	<?php endforeach;?>
			      </td>
			    </tr>
			   <?php 
					endforeach;
			   ?>
			</tbody>
			</table>
			<?php endif ?>
		</td>
	</tr>
	<tr>
		<th>数量：</th> 
		<td><input type="text" name="number" class="input-style" value="1" autocomplete="off"></td>
		</tr>
</tbody>
</table>
</div>
<div class="bk15"></div>
<input type="hidden" value="" name="product_id" id="product_id">
    <input name="addsubmit" type="submit" value="加入订单"  class="button" id="addsubmit" />
</form>
</div>
</div>
</body>
</html>
<script type="text/javascript">

function add_new_product(){
	product_sn = $('#product_sn').val();
	if(product_sn){
		$.getJSON('<?php echo U('order/get_product_info_ajax');?>',{sn:product_sn,language_id:<?php echo $order['language_id']?>}, function(result){
				if(result.error==1){
					alert(result.message);
				}else{
					product = result.content;
					$('#product_id').val(product.id);
					$('#goods_name').html(product.name);
					$('#sell_price').html(product.sell_price);
					$('#stock').html(product.stock);
					//$('#goods_attr').html(product.goods_attr);
					getGoodsInfoResponse(result.content);
				}
		});
	}
}
function getGoodsInfoResponse(result)
{

  // 显示属性
  var specCnt = 0; // 规格的数量
  var attrHtml = '';
  var attrType = '';
  var attrTypeArray = '';
  var attrCnt = result.attr_list.length;
  for (i = 0; i < attrCnt; i++)
  {
    var valueCnt = result.attr_list[i].length;

    // 规格
    if (valueCnt > 1)
    {
      attrHtml += result.attr_list[i][0].attr_name + ': ';
      for (var j = 0; j < valueCnt; j++)
      {
        switch (result.attr_list[i][j].attr_type)
        {
          case '0' :
          case '1' :
            attrType = 'radio';
            attrTypeArray = '';
          break;

          case '2' :
            attrType = 'checkbox';
            attrTypeArray = '[]';
          break;
        }
        attrHtml += '<input type="radio" name="spec_' + specCnt + attrTypeArray + '" value="' + result.attr_list[i][j].product_attr_id + '"';
        if (j == 0)
        {
          attrHtml += ' checked';
        }
        attrHtml += ' />' + result.attr_list[i][j].attr_value;
        if (result.attr_list[i][j].attr_price > 0)
        {
          attrHtml += ' [+' + result.attr_list[i][j].attr_price + ']';
        }
        else if (result.attr_list[i][j].attr_price < 0)
        {
          attrHtml += ' [-' + Math.abs(result.attr_list[i][j].attr_price) + ']';
        }
      }
      attrHtml += '<br />';
      specCnt++;
    }
    // 属性
    else
    {
      attrHtml += result.attr_list[i][0].attr_name + ': ' + result.attr_list[i][0].attr_value + '<br />';
    }
  }
  $('#spec_count').val(specCnt);
  document.getElementById('goods_attr').innerHTML = attrHtml;
}

</script>